<template>
  <t-dialog :header="header" :visible.sync="visible" :onClose="closeDialog" :closeOnOverlayClick="false"
    :confirmBtn="null" width="90%" top="5%">
    <div style="height: 60vh">
      <t-tabs size="medium" v-model="tabValue">
        <!--    <t-tab-panel value="first" label="申报单位信息" :destroyOnHide="true">-->
        <!--    </t-tab-panel>-->
        <t-tab-panel value="1" label="基本信息" :destroyOnHide="true">
          <t-form labelWidth="160px">
            <t-row style="align-items: stretch" :gutter="14">
              <t-col :span="6">
                <t-card class="step-card" size="small" title="基本信息">
                  <t-form-item label="平台名称：" name="name">
                    {{ data.name }}
                  </t-form-item>
                  <t-form-item label="平台类别：" name="platformCategory">
                    {{ data.platformCategory | filterByDict(dict.type.platform_category) }}
                  </t-form-item>
                  <t-form-item label="地址：" name="address">
                    {{ data.address }}
                  </t-form-item>
                  <t-form-item label="邮编：" name="postCode">
                    {{ data.postCode }}
                  </t-form-item>
                  <t-form-item label="立项时间：" name="buildDate">
                    {{ data.buildDate }}
                  </t-form-item>
                  <t-form-item label="网址：" name="website">
                    {{ data.website }}
                  </t-form-item>
                  <t-form-item label="平台建设内容：" name="content">
                    {{ data.content }}
                  </t-form-item>
                </t-card>
              </t-col>
              <t-col :span="6">
                <t-card class="step-card" size="small" title="平台负责人">
                  <t-row>
                    <t-col :span="6">
                      <t-form-item label="姓名：" name="platformLeader.name">
                        {{ data.platformLeader.name }}
                      </t-form-item>
                      <t-form-item label="性别：" name="platformLeader.sex">
                        {{ data.platformLeader.sex | filterByDict(dict.type.sys_user_sex) }}
                      </t-form-item>
                      <t-form-item label="身份证号：" name="platformLeader.idCard">
                        {{ data.platformLeader.idCard }}
                      </t-form-item>
                      <t-form-item label="出生年月：" name="platformLeader.birthDate">
                        {{ data.platformLeader.birthDate }}
                      </t-form-item>
                      <t-form-item label="出生年月：" name="platformLeader.birthDate">
                        {{ data.platformLeader.birthDate }}
                      </t-form-item>
                      <t-form-item label="联系电话：" name="platformLeader.telephone">
                        {{ data.platformLeader.telephone }}
                      </t-form-item>
                      <t-form-item label="手机号码：" name="platformLeader.phone">
                        {{ data.platformLeader.phone }}
                      </t-form-item>
                      <t-form-item label="电子信箱：" name="platformLeader.email">
                        {{ data.platformLeader.email }}
                      </t-form-item>
                      <t-form-item label="学历：" name="platformLeader.education">
                        {{ data.platformLeader.education | filterByDict(dict.type.education) }}
                      </t-form-item>
                      <t-form-item label="专业：" name="platformLeader.majorName">
                        {{ data.platformLeader.majorName }}
                      </t-form-item>
                      <t-form-item label="职务：" name="platformLeader.duty">
                        {{ data.platformLeader.duty }}
                      </t-form-item>
                      <t-form-item label="职称：" name="platformLeader.profTit">
                        {{ data.platformLeader.profTit | filterByDict(dict.type.prof_tit) }}
                      </t-form-item>
                    </t-col>
                  </t-row>
                </t-card>
              </t-col>
              <t-col :span="6" style="margin-top: 10px;">
                <t-card class="step-card" size="small" title="平台联系人">
                  <t-row>
                    <t-col :span="6">
                      <t-form-item label="姓名：" name="platformLinker.name">
                        {{ data.platformLinker.name }}
                      </t-form-item>
                      <t-form-item label="联系电话：" name="platformLinker.telephone">
                        {{ data.platformLinker.telephone }}
                      </t-form-item>
                      <t-form-item label="手机号码：" name="platformLinker.phone">
                        {{ data.platformLinker.phone }}
                      </t-form-item>
                      <t-form-item label="电子信箱：" name="platformLinker.email">
                        {{ data.platformLinker.email }}
                      </t-form-item>
                      <t-form-item label="传真：" name="platformLinker.facsimile">
                        {{ data.platformLinker.facsimile }}
                      </t-form-item>
                    </t-col>
                  </t-row>
                </t-card>
              </t-col>
            </t-row>
          </t-form>
        </t-tab-panel>
        <t-tab-panel value="2" label="建设单位信息" :destroyOnHide="true">
          <t-form labelWidth="160px">
            <t-row style="align-items: stretch" :gutter="14">
              <t-col :span="12">
                <t-card class="step-card" size="small" title="建设单位信息">
                  <t-row style="align-items: stretch" :gutter="14">
                    <t-col :span="6">
                      <t-form-item label="姓名：" name="constructionUnit.name">
                        {{ data.constructionUnit.name }}
                      </t-form-item>
                      <t-form-item label="性别：" name="constructionUnit.sex">
                        {{ data.constructionUnit.sex | filterByDict(dict.type.sys_user_sex) }}
                      </t-form-item>
                      <t-form-item label="身份证号：" name="constructionUnit.idCard">
                        {{ data.constructionUnit.idCard }}
                      </t-form-item>
                      <t-form-item label="出生年月：" name="constructionUnit.birthDate">
                        {{ data.constructionUnit.birthDate }}
                      </t-form-item>
                      <t-form-item label="学历：" name="constructionUnit.education">
                        {{ data.constructionUnit.education | filterByDict(dict.type.education) }}
                      </t-form-item>
                      <t-form-item label="职务：" name="constructionUnit.duty">
                        {{ data.constructionUnit.birthDate }}
                      </t-form-item>
                      <t-form-item label="职称：" name="constructionUnit.profTit">
                        {{ data.constructionUnit.profTit | filterByDict(dict.type.prof_tit) }}
                      </t-form-item>
                      <t-form-item label="专业：" name="constructionUnit.majorName">
                        {{ data.constructionUnit.majorName }}
                      </t-form-item>
                      <t-form-item label="联系电话：" name="constructionUnit.telephone">
                        {{ data.constructionUnit.telephone }}
                      </t-form-item>
                      <t-form-item label="手机号码：" name="constructionUnit.phone">
                        {{ data.constructionUnit.phone }}
                      </t-form-item>
                      <t-form-item label="电子信箱：" name="constructionUnit.email">
                        {{ data.constructionUnit.email }}
                      </t-form-item>
                      <t-form-item label="科技管理部门名称：" name="constructionUnit.deptName">
                        {{ data.constructionUnit.deptName }}
                      </t-form-item>
                    </t-col>
                    <t-col :span="6">
                      <t-form-item label="科技管理部门名称：" name="constructionUnit.deptName">
                        {{ data.constructionUnit.deptName }}
                      </t-form-item>
                      <t-form-item label="科技管理部门电话：" name="constructionUnit.deptTelephone">
                        {{ data.constructionUnit.deptTelephone }}
                      </t-form-item>
                      <t-form-item label="科技管理部门传真：" name="constructionUnit.deptFacsimile">
                        {{ data.constructionUnit.deptFacsimile }}
                      </t-form-item>
                      <t-form-item label="科技管理部地址：" name="constructionUnit.deptAddress">
                        {{ data.constructionUnit.deptAddress }}
                      </t-form-item>
                      <t-form-item label="科技管理部门邮编：" name="constructionUnit.deptPostCode">
                        {{ data.constructionUnit.deptPostCode }}
                      </t-form-item>
                    </t-col>
                  </t-row>
                </t-card>
              </t-col>
            </t-row>
          </t-form>
        </t-tab-panel>
        <t-tab-panel value="3" label="立项背景与意义信息" :destroyOnHide="true">
          <t-row style="align-items: stretch" :gutter="14">
            <t-col :span="12">
              <t-card class="step-card" size="small" title="立项背景与意义">
<!--                <div class="content_style" v-html="data.platformBackground.background"></div>-->
                <inner-html :content="data.platformBackground.background"></inner-html>

              </t-card>
            </t-col>
          </t-row>
        </t-tab-panel>
        <t-tab-panel value="4" label="主要任务信息" :destroyOnHide="true">
          <t-row style="align-items: stretch" :gutter="14">
            <t-col :span="12">
              <t-card class="step-card" size="small" title="主要任务">
<!--                <div class="content_style" v-html="data.platformMainTask.mainTask"></div>-->
                <inner-html :content="data.platformMainTask.mainTask"></inner-html>

              </t-card>
            </t-col>
          </t-row>
        </t-tab-panel>
        <t-tab-panel value="5" label="经费预算信息" :destroyOnHide="true" v-if="!hideInfo">
          <!-- <t-row style="align-items: stretch" :gutter="14">
            <t-col :span="12">
              <project-unit v-model="data.projectCompanyList" :projectId="objId" :adviceFunding="data.adviceFunding" :editOpen="false"  phaseType="1"></project-unit>
            </t-col>
          </t-row> -->
          <platform-budget v-model="data.platformBudget" :container="'.t-tab-panel'" :platformId="objId" :fundingObj="fundingObj" :editOpen="false" phaseType="1"></platform-budget>
        </t-tab-panel>
        <t-tab-panel value="6" label="仪器设备经费概算信息" :destroyOnHide="true" v-if="!hideInfo">
        <t-row style="align-items: stretch" :gutter="14">
            <t-col :span="12">
<!--              <project-member v-model="data.platformEquipments" :projectId="objId" :editOpen="false" phaseType="1"></project-member>-->
              <platform-background-literature ref="project-background-literature"
                                              v-model="data.platformEquipments" :editOpen="false" :value="data.Equipments"></platform-background-literature>

            </t-col>
          </t-row>
        </t-tab-panel>
        <t-tab-panel value="7" label="委员会人员信息" :destroyOnHide="true">
          <t-row style="align-items: stretch" :gutter="14">
            <t-col :span="12">
              <t-card class="step-card" size="small" title="专家人员信息">
                <platform-member ref="platform-member"
                                 v-model="data.member1" :editOpen="false" :value="data.member1"></platform-member>
                <!--              <platform-member-technology ref="platform-member-technology"-->
                <!--                               v-model="data.member2" :editOpen="false" :value="data.member2"></platform-member-technology>-->
              </t-card>

            </t-col>
          </t-row>
          <t-row style="align-items: stretch" :gutter="14">
            <t-col :span="12">
              <t-card class="step-card" size="small" title="技术人员信息">
<!--              <platform-member ref="platform-member"-->
<!--                               v-model="data.member1" :editOpen="false" :value="data.member1"></platform-member>-->
              <platform-member-technology ref="platform-member-technology"
                                          v-model="data.member2" :editOpen="false" :value="data.member2"></platform-member-technology>
              </t-card>
            </t-col>
          </t-row>
        </t-tab-panel>
        <t-tab-panel value="8" label="建设单位的保障条件与经费配套信息" :destroyOnHide="true">
          <t-row style="align-items: stretch" :gutter="14">
            <t-col :span="12">
              <t-card class="step-card" size="small" title="建设单位的保障条件与经费配套信息">
<!--                <div class="content_style" v-html="data.platformSafeguard.background"></div>-->
                <inner-html :content="data.platformSafeguard.background"></inner-html>

              </t-card>
            </t-col>
          </t-row>
        </t-tab-panel>
        <t-tab-panel value="9" label="相关附件" :destroyOnHide="true">
          <t-row style="align-items: stretch" :gutter="14">
            <t-col :span="12">
              <t-card class="step-card" size="small" title="相关附件">
                <t-table row-key="id" :columns="projectFileColumns" :data="projectFileData">
                  <template #id="{row, rowIndex}">
                    {{ rowIndex+1 }}
                  </template>
                  <template  #op="{row}">
                    <div v-for="(item,index) in row.fileLists" :key="index">
                      <a class="t-button-link" target="_blank" :href="item.url" >
                        {{item.name}}
                      </a>
                    </div>
                  </template>
                </t-table>
              </t-card>
            </t-col>
          </t-row>
        </t-tab-panel>
      </t-tabs>
    </div>

  </t-dialog>
</template>

<script>
import { getFiles } from "@/api/common";
import platformBudget from "@/pages/tjpt/platform/components/platform-budget.vue";
import dayjs from "dayjs";
import PlatformBackgroundLiterature from "@/pages/tjpt/platform/components/platform-background-literature.vue";
import platformMember from "@/pages/tjpt/components/platform-member.vue";
import platformMemberTechnology from "@/pages/tjpt/components/platform-member-technology.vue";
import InnerHtml from "@/components/InnerHtml/index.vue";


export default {
  name: "platform-detail-dialog",
  dicts: ["project_type", "subject_classification", "sys_user_sex", "prof_tit", "degree", "duty", "platform_type", "member_type", "expect_result_type", "education", "platform_category"],
  components: {
    platformBudget,
    PlatformBackgroundLiterature,
    platformMember,
    platformMemberTechnology,
    InnerHtml
  },
  props: {
    objId: [String, Number],
    header: String,
    isDialog: {
      type: Boolean,
      default: true
    },
    hideInfo: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      projectFileData: [
        {
          id: 1,
          c1: "批复文件",
          c2: "否",
          moduleKey: "platformPFWJ",
          fileIds: [],
          fileLists: [],
        },
      ],
      projectFileColumns: [
        {
          colKey: "id",
          title: "序号",
          align: "center",
          width: 64
        },
        {
          colKey: "c1",
          title: "附件名称",
          align: "center",
        },
        {
          colKey: "c2",
          title: "是否必需",
          align: "center",
        },
        {
          colKey: "op",
          title: "附件列表",
          align: "left",
        },
      ],
      fundingObj: { subsidyFunding: 0, adviceFunding: 0 },
      disableDate: {},
      expectedResultsColumns: [
        {
          colKey: "sort",
          title: "序号",
          width: 64,
          align: "center",
        },
        {
          colKey: "expectResultTypeLabel",
          title: "成果类型",
          align: "center",
        },
        {
          colKey: "count",
          title: "数量",
          align: "center",
        },
      ],
      site_tag: import.meta.env.VITE_SITE_TAG,
      visible: true,
      tabValue: "1",
      // projectFileColumns: [
      //   {
      //     colKey: "id",
      //     title: "序号",
      //     align: "center",
      //     width: 64
      //   },
      //   {
      //     colKey: "c1",
      //     title: "附件名称",
      //     align: "center",
      //   },
      //   {
      //     colKey: "c2",
      //     title: "是否必需",
      //     align: "center",
      //   },
      //   {
      //     colKey: "op",
      //     title: "附件列表",
      //     align: "left",
      //   },
      // ],
      // projectFileData: [
      //   {
      //     id: 1,
      //     c1: "查新报告",
      //     c2: "是",
      //     moduleKey: "projectCXBG",
      //     fileIds: [],
      //     fileLists: [],
      //   },
      //   {
      //     id: 2,
      //     c1: "归口管理单位科研诚信承诺书",
      //     c2: "是",
      //     fileIds: [],
      //     fileLists: [],
      //     moduleKey: "projectCNS"
      //   },
      //   {
      //     id: 3,
      //     c1: "项目组科研诚信承诺书",
      //     c2: "是",
      //     fileIds: [],
      //     fileLists: [],
      //     moduleKey: "projectTeamCNS"
      //   },
      //   // {
      //   //   id: 4,
      //   //   c1: "已盖章申报书",
      //   //   c2: "审批通过之后，走完盖章流程后上传。",
      //   //   fileIds: [],
      //   //   fileLists: [],
      //   //   moduleKey: "projectSBS"
      //   // }
      // ],
      data: {
        name: "",
        platformCategory: "",
        address: "",
        postCode: "",
        buildDate: "",
        website: "",
        content: "",
        platformLeader: {
          name: "",
          sex: "",
          birthDate: "",
          education: "",
          duty: "",
          profTitId: "",
          profTit: "",
          majorName: "",
          telephone: "",
          phone: "",
          email: "",
        },
        platformLinker: {
          name: "",
          telephone: "",
          phone: "",
          email: "",
          facsimile: "",
        },
        constructionUnit: {
          name: "",
          sex: "",
          birthDate: "",
          education: "",
          duty: "",
          profTitId: "",
          profTit: "",
          majorName: "",
          telephone: "",
          phone: "",
          email: "",
          deptName: "",
          deptTelephone: "",
          deptFacsimile: "",
          deptAddress: "",
          deptPostCode: "",
        },
        platformBackground:{
          background:""
        },
        platformMainTask:{
          mainTask:""
        },
        platformBudget:{

        },
        platformEquipments:{

        },
        platformSafeguard:{

        }
      },
      projectCategoryOptions: []
    }
  },
  watch: {
    objId: {
      immediate: true,
      handler(val) {
        if (val) {
          this.getObj(val);
        }
      }
    },
  },
  methods: {
    async getObj() {
      await Promise.all([this.getDeclareTree()]);
      try {
        let allDetail1 = await this.$api.tjpt.project.getAll(this.objId)
        let member1 =  await this.$api.tjpt.project.getPlatformMemberByType(this.objId,"1")
        let member2 = await this.$api.tjpt.project.getPlatformMemberByType(this.objId,"2")
        let allDetail2 = await this.$api.tjpt.project.getSafeguardByPlatformId(this.objId)
        getFiles(this.objId).then((res) => {
          const files = {}
          res.data.forEach((item) => {
            if (!files[item.moduleKey]) {
              files[item.moduleKey] = []
            }
            files[item.moduleKey].push({
              name: item.fileName,
              url: item.fullFilePath,
              id: item.id,
              filePath: item.filePath
            })
          })
          this.projectFileData[0].fileLists = files.platformPFWJ || [];
          this.projectFileData[0].fileIds = files.platformPFWJ?.map(val => val.id) || [];
        }).catch((e) => {
          this.applyLoading = false;
          this.$message.error(e.toString());
        });
        Object.assign(this.data,allDetail1.data)
        this.data.member1 = member1.data
        this.data.member2 = member2.data
        this.data.platformSafeguard.background = allDetail2.data?.safeguardCondition
        console.log("allDetail2",allDetail2)
        // console.log('this.data',this.data)
      }catch (e){
        this.$message.error(e.toString());
      }

        // const isOwner = this.$store.state.user.userId === response.data.createUserId;
        // const isProjectSBS = isOwner && Number(response.data.projectStatus || 0) >= 6 && Number(response.data.projectStatus || 0) !== 7;
        // response.data.projectMembers = response.data.projectMembers || []
        // this.disableDate = {
        //   before: dayjs(response.data.startDate, "YYYY-MM-DD").endOf('month').subtract(1, 'month').format(),
        //   after: dayjs(response.data.endDate, "YYYY-MM-DD").endOf('month').subtract(0, 'month').format(),
        // }
        // this.fundingObj = {
        //   adviceFunding: response.data.adviceFunding,
        //   subsidyFunding: response.data.subsidyFunding
        // }

    },
    getDeclareTree() {
      return this.$api.kjxm.project.planCategoryTree().then(response => {
        this.projectCategoryOptions = response.data;
      }).catch((e) => {
        this.$message.error(e.toString());
      });
    },
    closeDialog() {
      this.$emit("update:visible", false);
    },
  }
}
</script>

<style lang="less" scoped>
.t-tab-panel {
  padding: 10px;
  height: 100%;
}

.t-form__item {
  margin-bottom: 6px
}

.t-row {
  margin-bottom: 14px;
}

.step-card {
  height: 100%;
  margin-bottom: 14px;
}

.content_style {
  font-size: 12pt;
  font-family: 宋体;
  line-height: 1.5;
}
</style>
